var fs = require('fs');


var myArgs = process.argv.slice(1);

var input = [];

var i = 0;
 
 
 var Item = new Array();
 var ListItems = new Array();
 var nbContacts = 0;
 var nbContactsDepart = 0;
 var V2C = true;
 var vcfFormat = 0;
 
                                
                                //*****************************************************************
                V2C = true;
                var i = 0;
                
                Item = [];                
        ListItems = [];
                //**************************************************************************
                ListItems["VERSION"] = "VERSION";
        ListItems["FN"] = "FN"; 
        ListItems["N"] = "N"; 
        ListItems["ChI"] = "PHOTO; ENCODING= BASE64; TYPE=JPEG";          
        ListItems["CATEGORIES"] = "CATEGORIES";
                
                if(vcfFormat == 0) {
            // VERSION:2.1
            var Tabi = new Array("TEL;HOME;CELL", "TEL;WORK;CELL", "TEL;X-CELL2", "TEL;HOME;VOICE", "TEL;WORK;VOICE", "TEL;X-VOICE2", "EMAIL;HOME","EMAIL;WORK", "EMAIL", "EMAIL;X-AUTRES","NOTE","ADR;HOME", "ADR;WORK", "BDAY", "WEBSITE", "URL");
        }
        else {
            // VERSION:3.0
            var Tabi = new Array("TEL;TYPE=HOME,CELL", "TEL;TYPE=WORK,CELL", "TEL;TYPE=X-CELL2", "TEL;TYPE=HOME,VOICE", "TEL;TYPE=WORK,VOICE", "TEL;TYPE=X-VOICE2", "EMAIL;TYPE=HOME", "EMAIL;TYPE=WORK", "EMAIL;TYPE=INTERNET", "EMAIL;TYPE=X-AUTRES", "NOTE", "ADR;TYPE=HOME", "ADR;TYPE=WORK", "BDAY", "WEBSITE", "URL");
                    
        }
        for(i=0;i<Tabi.length;i++) {
            ListItems[Tabi[i]]=Tabi[i];
        }
                //*******************************************************************************
                nbContactsDepart = 0;
                
                
                function ConvertDatasVcf2Csv(){    
                // variables locales
                var i = CountChar;
                var id = 0;
                var id2 = 0;
                var Tim2 = 0;       
                
                // ----------------------
                for (CountChar = i; CountChar < LenText; CountChar++) {
                    
                    id = Buffer.indexOf("BEGIN:VCARD",CountChar);                    
                    if (id == -1) {
                        // fin des vCards
                        CountChar = LenText + 1;
                        nbContacts = idLigne;
                        if (nbContacts<0) { alert("Aucun contact trouv\351 !");}
                        refreshTab("");
                        break;
                        // *************************************************************
                    }
                    else {
                            idLigne = idLigne + 1;
                            nbContactsDepart++;
                            decodeVcard(Buffer.substr(id, id2 - id));
                            CountChar = id2;
                            Tim2 = Chrono();                            
                            if(Tim2 - StartTime > 200) {return false;}
                     }
                                        
                }                
            }